package net.learntechnology.examples.service;

import com.google.inject.Inject;
import net.learntechnology.examples.dao.EmployeeDao;
import net.learntechnology.examples.domain.Employee;
import java.util.List;

/**
 *
 * @author nmaves
 */
public class EmployeeService {

    private EmployeeDao employeeDao;

    @Inject
    public EmployeeService(EmployeeDao employeeDao) {
        this.employeeDao = employeeDao;
    }

	public Employee get(Integer id) {
		return employeeDao.fetch(id);
	}

    public List<Employee> getAll() {
        return employeeDao.fetchAll();
    }

	public void delete(Integer id) {
		employeeDao.delete(id);
	}

	public Employee save(Employee employee) {
		if(employee.getId() == null) {
			employeeDao.insert(employee);
		} else {
			employeeDao.update(employee);
		}
		return employee;
	}
}
